;(function (window,$) {
    // 创建DragMenu对象
    function DragMenu(parSelector) {
        return new DragMenu.prototype.init(this,parSelector instanceof $.prototype.init ? parSelector : $(parSelector));
    }
    DragMenu.prototype = {
        constructor:DragMenu,
        init:function (el,parentNode) {
             this.startX = 0;
             this.listWidth = el.width();
             this.navWidth = parentNode.width();
             this.moveX = 0;
             this.el = el;
             el.on("mousedown",this.down.bind(this));
             el.on("tap",this.down.bind(this));
        },
        down:function (e) {
            var el = this.el.get(0);
            var that = this;
            function move(e) {
                that.moveX = e.changedTouches ? e.changedTouches[0].pageX - that.startX: e.pageX - that.startX;
                if (that.moveX >= 0) that.moveX = 0;
                if (that.moveX <= (that.navWidth - that.listWidth)) that.moveX =  that.navWidth - that.listWidth;
                that.el.css({marginLeft:that.moveX + "px"});
            }
            this.startX = e.changedTouches ? e.changedTouches[0].pageX - list.offsetLeft : e.pageX - list.offsetLeft;
            this.el.on("touchmove",move) ;
            this.el.on("mousemove",move) ;
            this.el.on("touchend",function () {
                el.removeEventListener("touchmove",move);
            }.bind(this));
            this.el.on("mouseup",function () {
                el.removeEventListener("mousemove",move);
            }.bind(this))
        }
    };
    DragMenu.prototype.init.prototype = DragMenu.prototype;
    // 给Utils进行扩展
    $.fn.extends({dragMenu:DragMenu});
})(window,Util);